/**
 * 系统设置 工作台
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/operationsummary/Operations' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>工作台</el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="创建时间：">
        <DateTimeRange @callFather="handleDateTimeRange"/>
      </el-form-item>
      <el-form-item label="接诊状态：">
        <el-select size="small" v-model="formInline.treatmentStatus" placeholder="接诊状态" @change="selectChange">
          <el-option label="所有" value=""></el-option>
          <el-option label="未就诊" value="未就诊" key="未就诊"></el-option>
          <el-option label="接诊中" value="接诊中" key="接诊中"></el-option>
          <el-option label="已完成" value="已完成" key="已完成"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="患者姓名：">
        <el-input size="small" v-model="formInline.name" placeholder="输入患者姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    


    <!--列表-->
    <div id="patientCard">
      <el-row>
        <el-col :span="7" v-for="(item, index) in listData" :key="item.id" :offset="index > -1 ? 1 : 0">
            <div id="container">
              <div>
                <div id="imgDiv">
                  <img src="../../assets/img/patientBoy.png" class="image">
                </div> 
                <div id="pInfo">
                  <span class="pname">&nbsp;&nbsp;{{item.name}}&nbsp;</span>
                  <span class="pinfo">&nbsp;&nbsp;{{item.patientSex}}&nbsp;</span>
                  <span class="pinfo">&nbsp;&nbsp;{{item.patientAge}}&nbsp;&nbsp;&nbsp;</span>
                  <!--<span>&nbsp;{{item.treatmentStatus}}&nbsp;</span>-->
                  <el-button size="mini" type="warning" plain>{{item.treatmentStatus}}</el-button>
                  <br/>
                  <span class="pinfo">&nbsp;&nbsp;挂号时间：{{item.date}}&nbsp;</span>
                  <br/>
                  <span class="pinfo">&nbsp;&nbsp;科室：{{item.office}}&nbsp;</span>
                  <span class="pinfo">&nbsp;&nbsp;医生：{{item.doctorName}}&nbsp;</span>
                  <br/>
                  <span class="pinfo">&nbsp;&nbsp;手机号码：{{item.patientPhone}}&nbsp;</span>
                  
                </div>
              </div>

              <div>
                <el-button class="bottom" v-if="item.treatmentStatus=='未就诊'" type="primary" round @click="prescriptionCase(item.id,item.patientId,item.name,item.patientAge,item.patientSex,item.office,item.doctorName)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;接诊&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</el-button>
                <el-button class="bottom" v-if="item.treatmentStatus!='未就诊'" :disabled="true" type="primary" round @click="prescriptionCase(item.id,item.patientId,item.name,item.patientAge,item.patientSex,item.office,item.doctorName)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;接诊&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</el-button>
                <el-button class="bottom"  type="info" round @click="patientInfo(item.id,item.patientId,item.name,item.patientAge,item.patientSex)">&nbsp;&nbsp;&nbsp;患者信息&nbsp;&nbsp;&nbsp;</el-button>
                <br/>
                <br/>
                <br/>
                <br/>
              </div>
            </div>
        </el-col>
      </el-row>
    </div>
    
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    
  </div>
</template>

<script>

import Pagination from '../../components/PaginationForWorkbench'
import DateTimeRange from '../../components/DateTimeRange'
import axios from 'axios'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        id:'',
        number:'',
        name:'', 
        sex:'',
        age:'', 
        phone:'', 
        clinicId:'', 
        officeId:'', 
        roleId:'',
        token: localStorage.getItem('logintoken')
      },
      formInline: {
        page: 1,
        limit: 9,
        treatmentStatus:'',
        name: '',
        startDate: null,
        endDate:null,
        
        token: localStorage.getItem('logintoken')
      },
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 9,
        total: 9
      }
        
    }
  },
  // 注册组件
  components: {
    Pagination,
    DateTimeRange
  },
  /**
   * 创建完毕获取数据列表
   */
  created() {
    this.getdata(this.formInline);
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取员工列表
    getdata(parameter) {
      this.loading = true      
      axios.post('/api/register/selectCase',{
        "pageNum":parameter.page,
        "pageSize":parameter.limit,
        "name":parameter.name,
        "treatmentStatus":parameter.treatmentStatus,
        "startDate":parameter.startDate,
        "endDate":parameter.endDate
        })
        .then(res => {
          this.loading = false     
          console.log('结果是',res)     
          this.listData = res.data.data.list
          // 分页赋值
          this.pageparm.currentPage = this.formInline.page
          this.pageparm.pageSize = this.formInline.limit
          this.pageparm.total = res.data.data.total          
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.formInline.page=1;
      this.getdata(this.formInline)
    },
    handleDateTimeRange(param) {
      if(param!=null){
      this.formInline.startDate = param[0];
      this.formInline.endDate = param[1];

      console.log("formInline",this.formInline)
      }else{
      this.formInline.startDate = null;
      this.formInline.endDate = null;

      console.log("formInline",this.formInline)
      }
      this.getdata(this.formInline)
    },
    // 选择框改变后调用
    selectChange(){
      this.getdata(this.formInline)      
    },
    // 跳转到新增处方和病例页
    prescriptionCase(rId,pId,pName,pAge,pSex,office,doctorName){
      this.$router.push({
        path:"/workbench/prescriptionCase",
        query:{
          patientId: pId,
          registerId: rId,
          patientName:pName,
          patientAge:pAge,
          patientSex:pSex,
          office:office,
          doctorName:doctorName
        }
      })
        axios.post('/api/register/updateCase',{
          "id":rId,

          "treatmentStatus":"接诊中"
        })
        .then(res => {
              
              if (res.data.code==200) {
                
                this.$message({
                  type: 'success',
                  message: '接诊中！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.data.message
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('接诊失败，请稍后再试！')
            })


    },
    // 跳转至患者信息页面
    patientInfo(rId,pId,pName,pAge,pSex){
      this.$router.push({
        path:"/workbench/patientInfo",
        query:{
          patientId: pId,
          registerId: rId,
          patientName:pName,
          patientAge:pAge,
          patientSex:pSex
          }
      })
    }
  }
}
</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }
  .userRole {
    width: 100%;
  }


  .time {
    font-size: 13px;
    color: #999;
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 80px;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }

  #imgDiv{
    float:left;
  }

  #container{
    width:320px;
  }
  .pname{
    font-weight:900;
  }
  .pinfo{
    font-size:15px;
  }

  #patientCard{
    width:1200px
  }
</style>

 
 